﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Process[] p = Process.GetProcessesByName("QQ");//processname here
            string cpu = string.Empty;
            string info = string.Empty;

            PerformanceCounter pp = new PerformanceCounter();
            pp.CategoryName = "Process";
            pp.CounterName = "% Processor Time";
            pp.InstanceName = "QQ";//processname here
            pp.MachineName = ".";
            if (p.Length > 0)
            {
                foreach (Process pr in p)
                {
                    while (true)
                    {
                        info = pr.ProcessName + "Memory：" +
                                                (Convert.ToInt64(pr.WorkingSet64.ToString()) / 1024).ToString();
                        Console.WriteLine(info + "    CPU usage：" + Math.Round(pp.NextValue(), 2).ToString() + "%");
                        Thread.Sleep(1000);
                    }
                }
            }
        }
    }
}